<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
        
    <h:body>
        <ui:composition template="./../layout/page.xhtml">            
            <ui:define name="top">
            </ui:define>

            <ui:define name="content">
                <h2>Регистрация пользователя</h2>
                <hr />                
                <h:form id="frmRegistrationUser">
                    <h:panelGrid columns="4">
                        <p:outputLabel value="Организация" for="txtOrganization"/>
                        <p:selectOneMenu id="txtOrganization" required="true"
                                         styleClass="select_registration"
                                         requiredMessage="Не выбрана организация"
                                         filter="true" filterMatchMode="startsWith"
                                         valueChangeListener="#{mbVEmployee.selectOrganization}" >
                            <f:selectItem itemLabel="Выбирете организацию" 
                                          itemValue="#{null}" 
                                          noSelectionOption="true" />
                            <f:selectItems value="#{mbVOrganization.all}" 
                                           var="o" 
                                           itemLabel="#{o.name}" 
                                           itemValue="#{o.id}"/>                            
                            <p:ajax event="blur" rendered="orgError" />
                            <f:validateRequired/>
                        </p:selectOneMenu>

                        <p:commandButton value="..." styleClass="button" 
                                         action="#{mbVEmployee.setOrganizationEmployees()}"
                                         process="@this"/>
                        <p:message for="txtOrganization" showDetail="true" id="orgError" />

                        <p:outputLabel value="Фамилия" for="txtLastName"/>
                        <p:selectOneMenu id="txtLastName" required="true"
                                         styleClass="select_registration"
                                         requiredMessage="Не выбрана фамилия"
                                         filter="true" filterMatchMode="startsWith"
                                         valueChangeListener="#{mbVEmployee.selectLastname}" >
                            <f:selectItem itemLabel="Выбирете фамилию" 
                                          itemValue="#{null}" 
                                          noSelectionOption="true" />
                            <f:selectItems value="#{mbVLastName.all}" 
                                           var="ln" 
                                           itemLabel="#{ln.name}" 
                                           itemValue="#{ln.id}"/>
                            <p:ajax event="blur" rendered="lnError" />
                            <f:validateRequired/>
                        </p:selectOneMenu> 

                        <p:commandButton value="..." styleClass="button"
                                         action="#{mbVEmployee.setLastNameEmployees()}"
                                         process="@this"/>
                        <p:message for="txtLastName" showDetail="true" id="lnError" />

                        <p:outputLabel value="Имя" for="txtFirstName"/>
                        <p:selectOneMenu id="txtFirstName" required="true"
                                         styleClass="select_registration"
                                         requiredMessage="Не выбрано имя"
                                         filter="true" filterMatchMode="startsWith"
                                         valueChangeListener="#{mbVEmployee.selectFirstname}" >
                            <f:selectItem itemLabel="Выбирете имя" 
                                          itemValue="#{null}"
                                          noSelectionOption="true" />
                            <f:selectItems value="#{mbVFirstName.all}" 
                                           var="fn" 
                                           itemLabel="#{fn.name}" 
                                           itemValue="#{fn.id}"/>
                            <p:ajax event="blur" rendered="fnError" />
                            <f:validateRequired/>
                        </p:selectOneMenu>

                        <p:commandButton value="..." 
                                         styleClass="button"
                                         action="#{mbVEmployee.setFirstNameEmployees()}"
                                         process="@this" />
                        <p:message for="txtFirstName" showDetail="true" id="fnError" />

                        <p:outputLabel value="Отчество" for="txtMiddleName" />  
                        <p:selectOneMenu id="txtMiddleName" filter="true" 
                                         styleClass="select_registration"
                                         filterMatchMode="startsWith"
                                         valueChangeListener="#{mbVEmployee.selectMiddlename}">
                            <f:selectItem itemLabel="Выбирете отчество" 
                                          itemValue="#{null}"
                                          noSelectionOption="true" />
                            <f:selectItems value="#{mbVMiddleName.all}" 
                                           var="mn" 
                                           itemLabel="#{mn.name}" 
                                           itemValue="#{mn.id}"/>
                        </p:selectOneMenu>
                        <p:commandButton value="..." 
                                         styleClass="button"
                                         action="#{mbVEmployee.setMiddleNameEmployees()}"
                                         process="@this"/>
                        <h:panelGroup/>
                        <p:outputLabel value="Телефон (+7)" for="txtPhone" />
                        <p:inputMask id="txtPhone" label="Телефон (+7)" size="50"
                                     value="#{mbVEmployee.employees.phone}" mask="9999999999">
                            <f:validator validatorId="validatorEmpty"/>
                        </p:inputMask>
                        <h:panelGroup/>
                        <p:message for="txtPhone"/>
                        <p:outputLabel value="Адрес" for="txtAddress"/>
                        <p:inputText id="txtAddress" label="Адрес" size="50" 
                                     value="#{mbVEmployee.address.toString()}"
                                     readonly="true">
                        </p:inputText>     
                        <p:commandButton value="..." styleClass="button"
                                         actionListener="#{mbVEmployee.setAddressEmployees()}"
                                         process="@this">
                            <p:ajax event="dialogReturn" 
                                    listener="#{mbVEmployee.onAddressChosen}"
                                    update=":frmRegistrationUser:txtAddress"/>
                        </p:commandButton>
                        <h:panelGroup/>
                        <p:outputLabel value="СНИЛС" for="txtSNILS" />
                        <p:inputMask id="txtSNILS" label="СНИЛС" size="50" 
                                     value="#{mbVEmployee.employees.snils}" mask="999-999-999 99"/>
                        <h:panelGroup />
                        <h:panelGroup />
                        <p:outputLabel value="Номер аттестата КИ" for="txtAttestatKI" />
                        <p:inputText id="txtAttestatKI" label="txtAttestatKI"
                                     size="50" 
                                     value="#{mbVEmployee.employees.attestatki}" />
                        <h:panelGroup />
                        <h:panelGroup />
                        <p:outputLabel value="Эл. адрес почты" for="txtEMail" />
                        <p:inputText id="txtEMail" label="Эл. адрес почты" 
                                     size="50"
                                     value="#{mbVEmployee.employees.email}">
                            <f:validator validatorId="validatorEmail"/>
                        </p:inputText>  
                        <h:panelGroup />
                        <p:message for="txtEMail"/>
                        <p:outputLabel value="Пользователь" for="txtLogin" />
                        <p:inputText id="txtLogin" label="Пользователь" size="50"
                                     value="#{mbVEmployee.employees.login}">
                            <f:validator validatorId="validatorEmpty"/>
                        </p:inputText>  
                        <h:panelGroup />
                        <p:message for="txtLogin"/>
                        <p:outputLabel value="Пароль" for="txtPassword"/>
                        <p:password id="txtPassword" label="Пароль" size="50" 
                                    value="#{mbVEmployee.employees.password}">
                            <f:validator validatorId="validatorEmpty"/>
                        </p:password>  
                        <h:panelGroup />
                        <p:message for="txtPassword"/>
                        <p:commandButton value="Принять" 
                                         action="#{mbVEmployee.saveEmployee()}"
                                         update="frmRegistrationUser"/>
                    </h:panelGrid>
                </h:form>
                <p:dialog header="Информация об организации" widgetVar="dialogNewOrganization" 
                          height="50%" width="50%" modal="false" resizable="false">
                    <ui:include src="/employee/new_organization.xhtml"/>
                    <p:ajax event="close" update="frmRegistrationUser:txtOrganization"/>
                </p:dialog>
                <p:dialog header="Фамилия" widgetVar="dialogNewLastName" modal="false" 
                          height="50%" width="50%" resizable="false">
                    <ui:include src="/fio/new_lastname.xhtml"/>
                    <p:ajax event="close" update="frmRegistrationUser:txtLastName"/>
                </p:dialog>
                <p:dialog header="Имя" widgetVar="dialogNewFirstName" modal="false" 
                          height="50%" width="50%" resizable="false">
                    <ui:include src="/fio/new_firstname.xhtml"/>
                    <p:ajax event="close" update="frmRegistrationUser:txtFirstName"/>
                </p:dialog>
                <p:dialog header="Отчество" widgetVar="dialogNewMiddleName" modal="false" 
                          height="50%" width="50%" resizable="false">
                    <ui:include src="/fio/new_middlename.xhtml"/>
                    <p:ajax event="close" update="frmRegistrationUser:txtMiddleName"/>
                </p:dialog>
                <!--
                <p:dialog id="dlgAddress" header="Адрес" widgetVar="dialogAddress" modal="true"
                          width="800px" resizable="false" >
                    <ui:include src="/fias/address.xhtml"/>
                    <p:ajax event="close" update=":frmRegistrationUser:txtAddress frmOrganization:txtAddress" />
                </p:dialog>
                -->
            </ui:define>

            <ui:define name="bottom">
            </ui:define>

        </ui:composition>
    </h:body>
</html>

